package org.uim.cricket.analyzer.parsers.partnerships.impl;

import java.util.ArrayList;
import java.util.List;

import org.uim.cricket.analyzer.parsers.partnerships.AbstractFallOfWicketsParser;
import org.uim.cricket.analyzer.parsers.partnerships.FallOfWicketParsable;
import org.uim.cricket.entities.partnerships.FallOfWicket;
import org.uim.cricket.util.HTMLStringUtils;
import org.uim.cricket.util.MyStringUtils;

public class FallOfWicketsParser extends AbstractFallOfWicketsParser {

    public FallOfWicketsParser(FallOfWicketParsable theFallOfWicketParser) {
        super(theFallOfWicketParser);
    }

    @Override
    public List<FallOfWicket> parseAllFallOfWickets(String source) {
        if (source == null) {
            return null;
        }
        
        ArrayList<FallOfWicket> wickets = new ArrayList<FallOfWicket>();
        String[] fows = MyStringUtils.splitInBetween(source, "<span", "</span>");

        for (int i = 0; i < fows.length; i++) {
            String tmp = HTMLStringUtils.cleanHTMLTags("<" + fows[i], true);
            FallOfWicket fow = super.getFallOfWicketParser().parseFallOfWicket(tmp);
            if (fow != null) {
                wickets.add(fow);
            }
        }

        return wickets;
    }

}
